package grammer.objectMatcher;

import grammer.phrase.Phrase;
import grammer.phrase.PhraseBuilder;
import grammer.phrase.PhraseEvaluator;

import java.util.Vector;

import action.ActionBuilder;

/**
 * 
 * @author Minodor
 * 
 *         Creates an Action from a line of the scenario
 */

public class TokenMatcher {

	private ActionBuilder ab;
	private Vector<String> currentLine;
	private PhraseBuilder pBuilder;
	private PhraseEvaluator pEvaluator;

	public TokenMatcher() {
		pBuilder = new PhraseBuilder();
		pEvaluator = new PhraseEvaluator();
		ab = new ActionBuilder();
	}

	public boolean Handle(Vector<String> currentLine, int line) {

		Phrase nextPhrase = pBuilder.buildPhrase(currentLine, line);
		if(nextPhrase!=null){
		int result = pEvaluator.eval(nextPhrase);
		if( result!=(-1)){
		ab.createAction(nextPhrase, result);
		return true;
		}
		else return false;}
		else return false;
	}

	public boolean startsWith(String string) {
		if (currentLine.get(0).equalsIgnoreCase(string))
			return true;
		return false;
	}
}
